package com.springcloud.device.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.feign.client.DeviceClient;
import com.feign.client.DeviceTypeService;
import com.service.base.ResponseResult;
import com.service.bean.Device;

@Controller
@CrossOrigin
@RequestMapping("/device")
public class DeviceController {
	
	@Autowired
    private DeviceClient deviceClient;
	
	@Autowired
    private DeviceTypeService deviceTypeService;
	
	
	//to index link
	@RequestMapping(value = "/index" )
	public String index(ModelMap map) {
		map.addAttribute("list",deviceTypeService.getDeviceTypeList());
		return "/device/index";
	}
	
	@ResponseBody
	@RequestMapping(value = "/register" )
	public ResponseResult register(@RequestParam("ids")Integer[] ids,@RequestParam("typeId") Integer typeId) {
		return deviceClient.register(ids, typeId);
	}
	
	@ResponseBody
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    public ResponseResult getList(Device device,
								  @RequestParam(defaultValue = "1") Integer pageNumber,
								  @RequestParam(defaultValue = "10") Integer pageSize){
        return deviceClient.getPage(device, pageNumber, pageSize);
    }
	
	
}
